package pers.mine.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import pers.mine.admin.service.SysUserService;
import pers.mine.nook.MsgException;

/**
 * 权限视频过滤器
 * @author Mine
 * @since 2017年5月28日_下午10:52:23
 */
@Component
public class FrontVideoFifter implements Filter{
	
	@Autowired
	private SysUserService sysUserService;

	public void setSysUserService(SysUserService sysUserService) {
		this.sysUserService = sysUserService;
	}

	@Override
	public void init(FilterConfig filterConfig) throws ServletException {
		System.out.println("FrontVideoFifter(权限视频过滤器)已初始化...");
	}

	@Override
	public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain chain) throws IOException, ServletException {
		HttpServletRequest xRequest = (HttpServletRequest) request;
		String  targetUrl = xRequest.getRequestURL().toString();
		System.out.println(">>>FrontVideoFifter---[来源URL:"
				+ xRequest.getHeader("Referer") + "]---[请求URL:"
				+ xRequest.getRequestURL() + "]");
	/*	try {
			//截取视频id
//			String[] tempStrs  = targetUrl.split("/");
//			String id = null;
//			if(tempStrs!=null){
//				 id=tempStrs[tempStrs.length].split(".")[0];
//			}
//			System.out.println(id);
			//验证管理员是否登录
			//验证会员是否登录
			
		//	System.out.println(sysUserService.findOneById("admin"));
		} catch (MsgException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}*/
		chain.doFilter(request, response);
	}

	@Override
	public void destroy() {
		System.out.println("FrontVideoFifter(权限视频过滤器)已销毁...");
	}

}
